//
//  TSDynamicController.m
//  TaShuo
//
//  Created by N-X on 2018/3/22.
//  Copyright © 2018年 MRNAN. All rights reserved.
//

#import "TSDynamicController.h"
#import "NXSegementPageView.h"
#import "TestViewController.h"


@interface TSDynamicController ()<NXSegementPageDelegate>
@property(nonatomic,copy)NSArray * titles;

@end

@implementation TSDynamicController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.titles = @[@"笔记推荐",@"母婴",@"美容护肤",@"营养保健",@"轻奢主义",@"奶粉",@"脑残必备",@"型男都必须毕本"];
    
    NXSegementTitleStyle * style = [[NXSegementTitleStyle alloc]init];
    style.margin = 20;
    style.isScrollLine = YES;
    style.scrollLineHeight = 2;
    style.scrollLineColor = [UIColor redColor];
    style.normalTitleColor = [UIColor blackColor];
    style.selectedTitleColor = [UIColor redColor];
    style.gradualChangeTitleColor = YES;
    
    NXSegementPageView * pageView = [[NXSegementPageView alloc]initWithFrame:CGRectMake(0,0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - self.navigationBarHeight - self.tabBarHeight) titles:self.titles parentViewController:self segementStyle:style delegate:self];
    [self.view addSubview:pageView];
}

#pragma mark - NXSegementPageDelegate

- (NSInteger)numberOfChildrenViewControllers
{
    return self.titles.count;
}

- (UIViewController *)segementController:(UIViewController *)reuseSegementController index:(NSInteger)index{
    
    UIViewController * currentViewController = reuseSegementController;
    if (!currentViewController) {
        if (index % 2 == 0) {
            currentViewController = [[UIViewController alloc]init];
            currentViewController.view.backgroundColor = [UIColor orangeColor];
        }else
        {
            currentViewController = [[TestViewController alloc]init];
        }
    }
    return currentViewController;
}
@end
